

#include "stdafx.h"
#include "pf_dialogfactory.h"
#include "pf_debug.h"

PF_DialogFactory* PF_DialogFactory::uniqueInstance = NULL;
    


/**
 * Private constructor.
 */
PF_DialogFactory::PF_DialogFactory() {
	PF_DEBUG->print("PF_DialogFacgory::PF_DialogFactory");
	factoryObject = NULL;
	PF_DEBUG->print("PF_DialogFacgory::PF_DialogFactory: OK");
}



/**
 * @return Instance to the unique font list.
 */
PF_DialogFactory* PF_DialogFactory::instance() {
    PF_DEBUG->print("PF_DialogFactory::instance()");
    if (uniqueInstance==NULL) {
        uniqueInstance = new PF_DialogFactory();
    }

    PF_DEBUG->print("PF_DialogFactory::instance(): OK");

    return uniqueInstance;
}



/**
 * Sets the real factory object that can create and show dialogs.
 */
void PF_DialogFactory::setFactoryObject(PF_DialogFactoryInterface* fo) {
    PF_DEBUG->print("PF_DialogFactory::setFactoryObject");
    factoryObject = fo;
    PF_DEBUG->print("PF_DialogFactory::setFactoryObject: OK");
}



/**
 * @return Factory object. This is never NULL. If no factory
 * object was set, the default adapter will be returned.
 */
PF_DialogFactoryInterface* PF_DialogFactory::getFactoryObject() {
	PF_DEBUG->print("PF_DialogFactory::getFactoryObject");
    if (factoryObject!=NULL) {
		PF_DEBUG->print("PF_DialogFactory::getFactoryObject: "
			"returning factory object");
        return factoryObject;
    } else {
		PF_DEBUG->print("PF_DialogFactory::getFactoryObject: "
			"returning adapter");
        return &factoryAdapter;
    }
}



void PF_DialogFactory::commandMessage(const PF_String& m) {
	PF_DEBUG->print("PF_DialogFactory::commandMessage");

    if (factoryObject!=NULL) {
		factoryObject->commandMessage(m);
	}
}
